package cn.itsource.campus.config;

import cn.itsource.campus.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class InterceptorWebMvcConfigurer implements WebMvcConfigurer {

    @Autowired
    private LoginInterceptor loginInterceptor;

    /**
     * 添加拦截器(让哪些拦截器生效)
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //让loginInterceptor生效，该拦截器，拦截所有的请求
        registry.addInterceptor(loginInterceptor)
                .addPathPatterns("/**")  //拦截所有的请求
                .excludePathPatterns("/login");//登录资源不拦截
    }
}
